#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json

# print(json.__all__)
'''
1. load: 从文件流fp中读取JSON串, 将其恢复成Python对象, 其中fp是一个支持write()方法的类文件对象
2. loads:将JSON串恢复成Python对象
3. dump: 将Python对象转换成JSON串, 输出到fp文件流中, fp是一个支持write()的类文件对象
4. dumps:把Python对象转换成JSON串
                load/loads==>
JSON字符串========================Python对象
                <==dump/dumps

'''

json_str = '{"employees":[{"first name":"Bill", "last name":"Gates"}, {"first name":"zhang", "last name":"san"}]}'
print(type(json_str))  # <class 'str'>
# loads: 将JSON串恢复成Python对象
py_obj1 = json.loads(json_str)
print(json_str)
print(py_obj1)
print(type(py_obj1))  # <class 'dict'>

print('==========================')
with open('json2python.json') as f:
    # load: 从文件流fp中读取JSON串, 将其恢复成Python对象, 其中fp是一个支持write()方法的类文件对象
    py_obj2 = json.load(f)
    print(py_obj2)
    print(type(py_obj2))  # <class 'dict'>
    print(py_obj2['employees'][0]['last name'])
